package useTool;
import Tool.Client;
import Tool.Linda;

import java.util.Date;
import java.util.Scanner;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;

public class ConnectToServer {
	public static void For_inAsyn_test(Object[] result)
	{
		if(result.length>0)
		{
			String ss="";
			float[][] result_result;
			for(int j=0;j<result.length;j++)
			{
				result_result = (float[][])result[j];
				for(int i = 0;i<result_result.length;i++)
				{
					for(int k=0;k<result_result[i].length;k++)
					{
						ss = ss +" "+ result_result[i][k];
					}
					System.out.println(ss);
					ss="";
				}
			}	
		}
		else
		{
			System.out.println("The number of row is not as the same as the number of column");
		}
	}
	
public static void main(String[] args){
	float[] row1=new float[]{1,2,3};
	float[] row2=new float[]{2,3,4};
	float[] row3=new float[]{3,4,5};
	
	float[] column1=new float[]{1,2,3};
	float[] column2=new float[]{2,3,4};
	float[] column3=new float[]{3,4,5};
	
	Client a=new Client();
	a.out("row-3*3", new Object[]{row1,row2,row3});
//	a.out("column-3*3", new Object[] {column1,column2});
	a.out("column-3*3",new Object[]{column1,column2,column3});
	
//	############Here is for the inAsyn version
	Future<Object> result = a.inAsyn("result");
	while(!result.isDone())
	{
		long time = System.currentTimeMillis();
		System.out.println("Now the time is "+ new Date(time));
	}
	Object object = null;
	try {
		object = result.get();
	} catch (InterruptedException | ExecutionException e) {
		e.printStackTrace();
	}
	ConnectToServer.For_inAsyn_test((Object[])object);
	a.close();
//	############Here is for the inAsyn version
	
	
//	###################Here is for the in-syn version
//	String ss="";
//	Object[] result = (Object[])a.in("result");
//	if(result.length >0)
//	{
//		float[][] result_result;
//		for(int j=0;j<result.length;j++)
//		{
//			System.out.println(result[j].getClass());
//			System.out.println("!!!!!!!!!!!!!!!!!!");
//			result_result = (float[][])result[j];
//			System.out.println(result_result);
//			for(int i = 0;i<result_result.length;i++)
//			{
//				for(int k=0;k<result_result[i].length;k++)
//				{
//					ss = ss +" "+ result_result[i][k];
//				}
//				System.out.println(ss);
//				ss="";
//			}
//		}	
//	}
//	else
//	{
//		System.out.println("The number of row is not as the same as the number of column");
//	}
//	a.close();
//	######################Here is for the in-syn version
}
}